$(function(){
    $('#submit').on('click', function(e){
        submitCard();
    });
    $('#goback').on('click', function(e){
        window.location.href = '/user/'+userId;
    })
})
function submitCard(){
    var btn = $(this);
    var cardId = $('#cardId').val();
    var name = $.trim($('#name').val()),
        company = $.trim($('#company').val()),
        position = $.trim($('#position').val()),
        mobile = $.trim($('#mobile').val()),
        email = $.trim($('#email').val()),
        business = $.trim($('#business').val()),
        address = $.trim($('#address').val()),
        product = $.trim($('#product').val());
    if(name === ''){
        $('#name').parent().addClass('has-error');
        AlertBox.showTip('请留下名号');
        return;
    }
    $('#name').parent().removeClass('has-error')
    /*if(company === ''){
        $('#company').parent().addClass('has-error');
        AlertBox.showTip('来自火星？');
        return;
    }
    $('#company').parent().removeClass('has-error')
    if(position === ''){
        $('#position').parent().addClass('has-error');
        AlertBox.showTip('不是老板也没关系');
        return;
    }
    $('#position').parent().removeClass('has-error')*/
    btn.button('loading');
    $.post('/saveCard', {
        name: name,
        company: company,
        position: position,
        mobile: mobile,
        email: email,
        business: business,
        address: address,
        product: product,
        cardId: cardId }, function(res){
        if(!res.error){
            if(res.forwardUrl){
                window.location.href = res.forwardUrl;
            }else{
                window.location.href = '/user';
            }
            /*if($('#cardId').val() === ''){
                AlertBox.showConfirm('保存成功！', {ok:'返回',cancel:'再来一个'}, function(){
                    window.location.href = '/user/'+userId;
                }, function(){
                    window.location.href = '/newCard';
                })
            }else{
                window.location.href = '/user/'+userId;
            }*/
        }else{
            AlertBox.showTip('出问题了...');
            btn.button('reset');
        }
    })
}